package cn.koala.key;

import cn.seed.web.config.XssStringJsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * 项目启动类
 * @author 32415
 *
 */
@SpringBootApplication
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
@EnableAsync
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
	
	/**
	 * 描述 : xssObjectMapper
	 * 
	 * @param builder
	 * @return ObjectMapper
	 */
	  @Bean
	  @Primary
	  public ObjectMapper xssObjectMapper(Jackson2ObjectMapperBuilder builder) {
	    //解析器
	    ObjectMapper objectMapper = builder.createXmlMapper(false).build();
	    //注册xss解析器
	    SimpleModule xssModule = new SimpleModule("XssStringJsonSerializer");
	    xssModule.addSerializer(new XssStringJsonSerializer());
	    objectMapper.registerModule(xssModule);
	    //返回
	    return objectMapper;
	  }
}
